package com.onluy.frameworkcloud.base;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.onluy.frameworkcloud.Param.IPagination;

import java.util.List;

public abstract class AppService<T> {
    public   abstract AppMapper  mapper();

    public   T model(T entity) {
        return (T) mapper().selectByPrimaryKey(entity);
    };
    public  int add(T entity){
        return mapper().insertSelective(entity);
    };
    public  int update(T entity){
        return  mapper().updateByPrimaryKeySelective(entity);
    };
    public  int del(T entity){
        return mapper().deleteByPrimaryKey(entity);
    };


    public     PageInfo<T> list (T entity, IPagination pagination){
        //使用分页插件,核心代码就这一行
        PageHelper.startPage(pagination.getCurrPage(), pagination.getPageSize());
        List<T> list=mapper().list(entity);
        // 获取
        return new PageInfo<T>(list);
    }

    public   List<T> list(T entity){
        return mapper().list(entity);
    }


    public     PageInfo<T> simplelist(T entity, IPagination pagination){
        //使用分页插件,核心代码就这一行
        PageHelper.startPage(pagination.getCurrPage(), pagination.getPageSize());
        List<T> list=mapper().list(entity);
        // 获取
        return new PageInfo<T>(list);
    }

    public   List<T> simplelist(T entity){
        return mapper().list(entity);
    }


    public List<T> treelist(T entity){
        List<T>  list =mapper().treelist( entity);
        return list;
    };

    public  List<T> navlist(T entity){
        List<T>  list =mapper().navlist( entity);
        return list;
    };

}
